const generateNonceString = (length) => {
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  var maxPos = chars.length;
  var noceStr = "";
  for (var i = 0; i < (length || 32); i++) {
    noceStr += chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return noceStr;
};

const startPayment = (prepayId, timeStamp, nonceStr, sign, signType, callback) => {
  const params = {
    timeStamp: timeStamp.toString(),
    nonceStr: nonceStr,
    'package': 'prepay_id=' + prepayId,
    signType: signType,
    paySign: sign,
    success: function (res) {
      if (callback != null) callback(true);
    },
    fail: function (res) {
      if (callback != null) callback(false);
    },
    complete: function (res) { }
  }
  console.log(params);
  wx.requestPayment(params);
}

module.exports = {
  startPayment: startPayment,
}